package cn.yunhe.controller;

import cn.yunhe.entity.Car;
import cn.yunhe.entity.Driver;
import cn.yunhe.service.ICarService;
import cn.yunhe.service.IDriverService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/after/SearchCarById")
public class SearchCarById extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ICarService carService = new ICarService();
        int indexId = Integer.parseInt(request.getParameter("indexId"));
        //通过id 查询到自定车辆信息
        Car car = carService.getCarById(indexId);

        IDriverService driverService = new IDriverService();
        //获取所有司机信息
        List<Driver> drivers = driverService.getAllDriver();

        request.getSession().setAttribute("searchCar", car);
        request.setAttribute("drivers",drivers);
        request.getRequestDispatcher("/after/feedbackpro-update.jsp").forward(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
